package dao;

import entity.Message;
import org.apache.ibatis.session.SqlSession;

import java.util.List;


public class MessageDao extends BaseDao{

    public List<Message> getTopMessages(int num) {
        SqlSession session = sqlSessionFactory.openSession();
        List<Message> messages;
        try {
            messages = session.selectList("Message.queryTopMessages", num);
        } finally {
            session.close();
        }
        return messages;
    }

    public List<Message> getAllMessages() {
        SqlSession session = sqlSessionFactory.openSession();
        List<Message> messages;
        try {
            messages = session.selectList("Message.queryAllMessages");
        } finally {
            session.close();
        }
        return messages;
    }

    public Message getMessagebyId(int id) {
        SqlSession session = sqlSessionFactory.openSession();
        Message message;
        try {
            message = session.selectOne("Message.queryMessagebyId", id);
        } finally {
            session.close();
        }
        return message;
    }
}
